function setAllStations(param) {
    var temp = "";
    if (param == '区域自动站') {
        $.getJSON("/zs/assets/json/quyuzidongStations.json", function (data) {
            $.each(data, function (i, item) {
                temp += (item.StationId + ',');
            });
            $('#c_stations').val(temp);
        });
    }
    else if (param == '水文站') {
        $.getJSON("/zs/assets/json/shuiwenStations.json", function (data) {
            $.each(data, function (i, item) {
                temp += (item.StationId + ',');
            });
            $('#c_stations').val(temp);
        });
    }
    else if (param == '大桥自动站') {
        $.getJSON("/zs/assets/json/daqiaoStations.json", function (data) {
            for (var i = 0; i < data.length; i++) {
                temp += (data[i].StationId + ',');
            }
            $('#c_stations').val(temp);
        });
    }
    else if (param == '浮标站') {
        $.getJSON("/zs/assets/json/fubiaoStations.json", function (data) {
            for (var i = 0; i < data.length; i++) {
                temp += (data[i].StationId + ',');
            }
            $('#c_stations').val(temp);
        });
    }
    else if (param == '部门共享站') {
        $.getJSON("/zs/assets/json/bumengongxiangStations.json", function (data) {
            $.each(data, function (i, item) {
                temp += (item.StationId + ',');
            });
            $('#c_stations').val(temp);
        });
    }
}

/**
 *
 * @param param stationType
 * **/
function showSelectStations(param) {
    var selectedStations = $('#c_stations').val().split(',');
    $('#c_checks').empty();
    $('#c_checks').append('<label style="margin-right: 5px"><input  onclick="checkAllStation(this)" type="checkbox"/>全选</label><br/>');
    if (param == '区域自动站') {
        $.getJSON("/zs/assets/json/quyuzidongStations.json", function (data) {
            if (selectedStations != null && selectedStations.length != 0) {
                for (var i = 0; i < data.length; i++) {
                    if (selectedStations.indexOf(data[i].StationId) != -1) {
                        $('#c_checks').append('<label style="margin-right: 5px"><input checked onclick="checkStation(this)" type="checkbox" value="' + data[i].StationId + '"/>' + data[i].StationName + '</label>');
                    } else {
                        $('#c_checks').append('<label style="margin-right: 5px"><input onclick="checkStation(this)" type="checkbox" value="' + data[i].StationId + '"/>' + data[i].StationName + '</label>');
                    }
                }
            } else {
                for (var i = 0; i < data.length; i++) {
                    $('#c_checks').append('<input style="margin-right: 5px" onclick="checkStation(this)" type="checkbox" value="' + data[i].StationId + '">' + data[i].StationName + '</input>');
                }
            }
        });
    }
    else if (param == '水文站') {
        $.getJSON("/zs/assets/json/shuiwenStations.json", function (data) {
            if (selectedStations != null && selectedStations.length != 0) {
                for (var i = 0; i < data.length; i++) {
                    if (selectedStations.indexOf(data[i].StationId) != -1) {
                        $('#c_checks').append('<label style="margin-right: 5px"><input checked onclick="checkStation(this)" type="checkbox" value="' + data[i].StationId + '"/>' + data[i].StationName + '</label>');
                    } else {
                        $('#c_checks').append('<label style="margin-right: 5px"><input onclick="checkStation(this)" type="checkbox" value="' + data[i].StationId + '"/>' + data[i].StationName + '</label>');
                    }
                }
            } else {
                for (var i = 0; i < data.length; i++) {
                    $('#c_checks').append('<input style="margin-right: 5px" onclick="checkStation(this)" type="checkbox" value="' + data[i].StationId + '">' + data[i].StationName + '</input>');
                }
            }
        });
    }

    else if (param == '大桥自动站') {
        $.getJSON("/zs/assets/json/daqiaoStations.json", function (data) {
            if (selectedStations != null && selectedStations.length != 0) {
                for (var i = 0; i < data.length; i++) {
                    if (selectedStations.indexOf(data[i].StationId) != -1) {
                        $('#c_checks').append('<label style="margin-right: 5px"><input checked onclick="checkStation(this)" type="checkbox" value="' + data[i].StationId + '"/>' + data[i].StationName + '</label>');
                    } else {
                        $('#c_checks').append('<label style="margin-right: 5px"><input onclick="checkStation(this)" type="checkbox" value="' + data[i].StationId + '"/>' + data[i].StationName + '</label>');
                    }
                }
            } else {
                for (var i = 0; i < data.length; i++) {
                    $('#c_checks').append('<input style="margin-right: 5px" onclick="checkStation(this)" type="checkbox" value="' + data[i].StationId + '">' + data[i].StationName + '</input>');
                }
            }
        });
    }
    else if (param == '浮标站') {
        $.getJSON("/zs/assets/json/fubiaoStations.json", function (data) {
            if (selectedStations != null && selectedStations.length != 0) {
                for (var i = 0; i < data.length; i++) {
                    if (selectedStations.indexOf(data[i].StationId) != -1) {
                        $('#c_checks').append('<label style="margin-right: 5px"><input checked onclick="checkStation(this)" type="checkbox" value="' + data[i].StationId + '"/>' + data[i].StationName + '</label>');
                    } else {
                        $('#c_checks').append('<label style="margin-right: 5px"><input onclick="checkStation(this)" type="checkbox" value="' + data[i].StationId + '"/>' + data[i].StationName + '</label>');
                    }
                }
            } else {
                for (var i = 0; i < data.length; i++) {
                    $('#c_checks').append('<input style="margin-right: 5px" onclick="checkStation(this)" type="checkbox" value="' + data[i].StationId + '">' + data[i].StationName + '</input>');
                }
            }
        });
    }
    else if (param == '部门共享站') {
        $.getJSON("/zs/assets/json/bumengongxiangStations.json", function (data) {
            if (selectedStations != null && selectedStations.length != 0) {
                for (var i = 0; i < data.length; i++) {
                    if (selectedStations.indexOf(data[i].StationId) != -1) {
                        $('#c_checks').append('<label style="margin-right: 5px"><input checked onclick="checkStation(this)" type="checkbox" value="' + data[i].StationId + '"/>' + data[i].StationName + '</label>');
                    } else {
                        $('#c_checks').append('<label style="margin-right: 5px"><input onclick="checkStation(this)" type="checkbox" value="' + data[i].StationId + '"/>' + data[i].StationName + '</label>');
                    }
                }
            } else {
                for (var i = 0; i < data.length; i++) {
                    $('#c_checks').append('<input style="margin-right: 5px" onclick="checkStation(this)" type="checkbox" value="' + data[i].StationId + '">' + data[i].StationName + '</input>');
                }
            }
        });
    }
}

/**
 *
 * @param param1 stationType
 * @param param2 county
 */

function showSelectStationsByCounty(param1, param2) {
    var selectedStations = $('#c_stations').val().split(',');
    $('#c_checks').empty();
    $('#c_checks').append('<label style="margin-right: 5px"><input  onclick="checkAllStation(this)" type="checkbox"/>全选</label><br/>');
    if (param1 == '区域自动站') {
        $.getJSON("/zs/assets/json/quyuzidongStations.json", function (data) {
            filterCounty(data, param2);
            if (selectedStations != null && selectedStations.length != 0) {
                for (var i = 0; i < data.length; i++) {
                    if (selectedStations.indexOf(data[i].StationId) != -1) {
                        $('#c_checks').append('<label style="margin-right: 5px"><input checked onclick="checkStation(this)" type="checkbox" value="' + data[i].StationId + '"/>' + data[i].StationName + '</label>');
                    } else {
                        $('#c_checks').append('<label style="margin-right: 5px"><input onclick="checkStation(this)" type="checkbox" value="' + data[i].StationId + '"/>' + data[i].StationName + '</label>');
                    }
                }
            } else {
                for (var i = 0; i < data.length; i++) {
                    $('#c_checks').append('<input style="margin-right: 5px" onclick="checkStation(this)" type="checkbox" value="' + data[i].StationId + '">' + data[i].StationName + '</input>');
                }
            }
        });
    }
    else if (param1 == '水文站') {
        $.getJSON("/zs/assets/json/shuiwenStations.json", function (data) {
            filterCounty(data, param2);
            if (selectedStations != null && selectedStations.length != 0) {
                for (var i = 0; i < data.length; i++) {
                    if (selectedStations.indexOf(data[i].StationId) != -1) {
                        $('#c_checks').append('<label style="margin-right: 5px"><input checked onclick="checkStation(this)" type="checkbox" value="' + data[i].StationId + '"/>' + data[i].StationName + '</label>');
                    } else {
                        $('#c_checks').append('<label style="margin-right: 5px"><input onclick="checkStation(this)" type="checkbox" value="' + data[i].StationId + '"/>' + data[i].StationName + '</label>');
                    }
                }
            } else {
                for (var i = 0; i < data.length; i++) {
                    $('#c_checks').append('<input style="margin-right: 5px" onclick="checkStation(this)" type="checkbox" value="' + data[i].StationId + '">' + data[i].StationName + '</input>');
                }
            }
        });
    }
    else if (param1 == '大桥自动站') {
        $.getJSON("/zs/assets/json/daqiaoStations.json", function (data) {
            if (selectedStations != null && selectedStations.length != 0) {
                for (var i = 0; i < data.length; i++) {
                    if (selectedStations.indexOf(data[i].StationId) != -1) {
                        $('#c_checks').append('<label style="margin-right: 5px"><input checked onclick="checkStation(this)" type="checkbox" value="' + data[i].StationId + '"/>' + data[i].StationName + '</label>');
                    } else {
                        $('#c_checks').append('<label style="margin-right: 5px"><input onclick="checkStation(this)" type="checkbox" value="' + data[i].StationId + '"/>' + data[i].StationName + '</label>');
                    }
                }
            } else {
                for (var i = 0; i < data.length; i++) {
                    $('#c_checks').append('<input style="margin-right: 5px" onclick="checkStation(this)" type="checkbox" value="' + data[i].StationId + '">' + data[i].StationName + '</input>');
                }
            }
        });
    }
    else if (param1 == '浮标站') {
        $.getJSON("/zs/assets/json/fubiaoStations.json", function (data) {
            if (selectedStations != null && selectedStations.length != 0) {
                for (var i = 0; i < data.length; i++) {
                    if (selectedStations.indexOf(data[i].StationId) != -1) {
                        $('#c_checks').append('<label style="margin-right: 5px"><input checked onclick="checkStation(this)" type="checkbox" value="' + data[i].StationId + '"/>' + data[i].StationName + '</label>');
                    } else {
                        $('#c_checks').append('<label style="margin-right: 5px"><input onclick="checkStation(this)" type="checkbox" value="' + data[i].StationId + '"/>' + data[i].StationName + '</label>');
                    }
                }
            } else {
                for (var i = 0; i < data.length; i++) {
                    $('#c_checks').append('<input style="margin-right: 5px" onclick="checkStation(this)" type="checkbox" value="' + data[i].StationId + '">' + data[i].StationName + '</input>');
                }
            }
        });
    }
    else if (param1 == '部门共享站') {
        $.getJSON("/zs/assets/json/bumengongxiangStations.json", function (data) {
            if (selectedStations != null && selectedStations.length != 0) {
                for (var i = 0; i < data.length; i++) {
                    if (selectedStations.indexOf(data[i].StationId) != -1) {
                        $('#c_checks').append('<label style="margin-right: 5px"><input checked onclick="checkStation(this)" type="checkbox" value="' + data[i].StationId + '"/>' + data[i].StationName + '</label>');
                    } else {
                        $('#c_checks').append('<label style="margin-right: 5px"><input onclick="checkStation(this)" type="checkbox" value="' + data[i].StationId + '"/>' + data[i].StationName + '</label>');
                    }
                }
            } else {
                for (var i = 0; i < data.length; i++) {
                    $('#c_checks').append('<input style="margin-right: 5px" onclick="checkStation(this)" type="checkbox" value="' + data[i].StationId + '">' + data[i].StationName + '</input>');
                }
            }
        });
    }
}


function filterCounty(data, param2) {
    if (param2 == '全部') {
        return data;
    }
    else if (param2 == '其它') {
        for (var i = data.length - 1; i >= 0; i--) {
            if (data[i].County != undefined) {
                data.splice(i, 1);
            }
        }
    }
    else {
        for (var i = data.length - 1; i >= 0; i--) {
            if (data[i].County != param2) {
                data.splice(i, 1);
            }
        }

    }
}

function checkStation(e) {
    var temp = $('#c_stations').val().split(',');

    if (!$(e).prop("checked")) {
        temp.splice(jQuery.inArray($(e).val(), temp), 1);
        $('#c_stations').val(temp);
    }
    else {
        $('#c_stations').val(temp + $(e).val() + ',');
    }
}

function checkAllStation(e) {
    var checks = $('#c_checks').find('input');
    var checksLen = $('#c_checks').find('input').length - 1;
    var tempArr = $('#c_stations').val().split(',');
    var temp = $('#c_stations').val();
    if (!$(e).prop("checked")) {
        checks.prop('checked', false);
        for (var i = 1; i < checksLen; i++) {
            tempArr.splice(jQuery.inArray($(checks[i]).val(), tempArr), 1);
        }
        $('#c_stations').val(tempArr);
    }
    else {
        checks.prop('checked', true);
        for (var j = 1; j < checksLen; j++) {
            if (tempArr.indexOf($(checks[j]).val()) < 0) {
                temp += $(checks[j]).val() + ','
            }
        }
        $('#c_stations').val(temp);
    }
}